home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / gold / pebMethods.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.5 KB  |  139 lines

  1. /*
  2.  * The original copyright owners of the accompanying source code files have
  3.  * agreed to place such code into the public domain.  Accordingly, anyone
  4.  * who receives or obtains a copy of such source code is freely entitled to
  5.  * reproduce, use and otherwise exploit such code (including the right to
  6.  * make derivative works), at his/her own risk and expense, without any
  7.  * obligation or liability to the original copyright owners.
  8.  *
  9.  * We would appreciate (but do not require) that the following message be
  10.  * included in any derivative works:
  11.  *
  12.  * "Portions of this program were developed by Peter Broadwell, Rob Myers
  13.  * and Robin Schaufler while working in Silicon Valley."
  14.  *
  15.  * The accompanying source code files and related documentation materials
  16.  * are distributed on an "AS IS" basis, without any warranties or
  17.  * guarantees of any kind.  All implied warranties, including the implied
  18.  * warranties of merchantability and of fitness for any particular purpose,
  19.  * are expressly disclaimed.
  20.  */
  21. #include "gl.h"
  22. #include "device.h"
  23. #include "geom.h"
  24. #include "class.h"
  25. #include "classIds.h"
  26. #include "selectors.h"
  27. #include "mbox.h"
  28. #include "individual.h"
  29. #include "behavior.h"
  30. #include "doers.h"
  31. #include "colors.h"
  32.  
  33. #include "pebbles.h"
  34.  
  35. extern model *stones[];
  36. extern pebbles pebbleTemplate;
  37. extern float sin(), cos();
  38.  
  39. #define PI 3.14159265358979323844
  40. #define DEG(x) ((float)x*(float)180/PI)
  41. #define RAD(x) ((float)x*PI/(float)180)
  42.  
  43.  
  44. /* ARGSUSED */
  45. floorinit(s, argtype, univol)
  46.     register pebbles *s;
  47.     int argtype;
  48.     point *univol;
  49. {
  50.     register model **stone = stones, *m = s->me.descr;
  51.     long *v;
  52.     point *pnts, *p;
  53.     int i, num, alpha;
  54.     register j, r;
  55.     float circumf, chord;
  56.  
  57.     s->floor.x = univol->x >> 1;
  58.     s->floor.y = univol->y >> 1;
  59.     s->floor.z = 0;
  60.     chord = 1200.0;
  61.     for(i = 0; i<STONES && m; i++, stone++, m = m->next, chord -= 80.0) {
  62.         /* make a prototype pebble */
  63.     makeobj((Object)stone);
  64.         pushmatrix();
  65.             scale(m->scale.x,m->scale.y,m->scale.z); /* */
  66.         fishColor(m->color);
  67.         /* setpattern(NO_TEXTURE); /* */
  68.         v = m->vertices;
  69.         pnts = m->points;
  70.         while(*v) {
  71.         p = &pnts[*(v++)];
  72.         pmvi(p->x, p->y, p->z);
  73.         while(*v) {
  74.             p = &pnts[*(v++)];
  75.             pdri(p->x, p->y, p->z);
  76.         }
  77.         pclos();
  78.         v++;
  79.         }
  80.         if (m->texture) {
  81.         fishColor(TEX_COLOR);
  82.         setpattern(m->texture);
  83.         v = m->vertices;
  84.         pnts = m->points;
  85.         while(*v) {
  86.             p = &pnts[*(v++)];
  87.             pmvi(p->x, p->y, p->z);
  88.             while(*v) {
  89.             p = &pnts[*(v++)];
  90.             pdri(p->x, p->y, p->z);
  91.             }
  92.             pclos();
  93.             v++;
  94.         }
  95.         setpattern(NO_TEXTURE);
  96.         fishColor(m->color);
  97.         }
  98.         /* */
  99.         popmatrix();
  100.     closeobj();
  101.  
  102.         /* make the real pebbles */
  103.     makeobj((Object)m);
  104.         pushLongName(s);
  105.         backface(FALSE);
  106.         fishWritemask(BACKGROUND);
  107.         fishColor(m->color);
  108.         pushmatrix();
  109. #define WIMP
  110. #ifdef WIMP
  111.         rotate(900,'y');
  112. #endif /* WIMP */
  113.         /* scale(3.0,3.0,1.5); /* */
  114.         translate((Coord)m->translate.x,
  115.                 (Coord)m->translate.y,
  116.                 (Coord)m->translate.z);
  117.         callobj((Object)stone);
  118.         for(r = 700; r < s->floor.x; r += 700) {
  119.         circumf = 2.0 * PI * (float)r;
  120.         num = (int)(circumf / chord);
  121.         alpha = (3600 / num);
  122.         rotate(-300, 'z');
  123.         for(j = 0; j < num; j++) {
  124.             rotate(alpha, 'z');
  125.             pushmatrix();
  126.             translate((Coord)r, 0.0, 0.0);
  127.             callobj((Object)stone);
  128.             popmatrix();
  129.         }
  130.         }
  131.         popmatrix();
  132.         backface(TRUE);
  133.         popLongName();
  134.         closeobj();
  135.         m->compiled = TRUE;
  136.         m->component = (Object)m;
  137.     }
  138. }
  139.